package com.base.andlangcore.mvvm

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding

/**
 * 基础的Frament
 */
abstract class AndLangFragment<VB : ViewBinding,VM : AndLangModel> : Fragment(){
    lateinit var vb: VB //ViewBinding
    val vm: VM by lazy { getVM() }//ViewModel

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        vb = getVB(inflater,container)
        initView()
        return vb.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData()
    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    //获取ViewBinding
    abstract fun getVB(inflater: LayoutInflater,
                                 container: ViewGroup?) : VB
    //获取ViewModel
    abstract fun getVM():VM

    abstract fun initView()
    abstract fun initData()

}